reduce is package {
 contract Reduce over %%f is {
    reducer has type ((%a, %b) => %b, %%f of %a, %b) => %b;
  };

  implementation Reduce over cons is {
    reducer is reduceCons;
  } using {
    reduceCons(f, nil, b) is b;
    reduceCons(f, cons(head, tail), b) is f(head, reducer(f, tail, b))
    using {
      f1(aa, bb) is reducer(f, aa, bb);
    };
  };
  
  main() do {
    L is cons of {1;2;3;4};
    
    K is reducer((function(X,Y) is X+Y), L, 0);
    
    logMsg(info,"K=$K");
    
    assert K=10;
  }
}